<include file="header"/>
<include file="loadding"/>
<style>
	/*::-moz-placeholder { color: #FF0000; }*/
	::-webkit-input-placeholder { color:#838B83; }
</style>
<script type="text/javascript">
    var flag = 0;
    var userType = "{BEESCRM:$userType}";
</script>
<body>
<div class="wraper wraper-btm">

	<div class="head clearfix" style="padding:5px;height:35px">
		<a href="javascript:history.go(-1);" class="iconfont icon-fanhui72 pull-left" style="height:100%;"></a>
		<span class="head-name pull-left" style="height:100%;">公益捐树</span>
		<a href="{BEESCRM::U('Communityhd/giveTree/orderList',array('tree_id' => $tree_id))}" class="pull-left text-right" style="height:100%;"><span class="iconfont icon-lishi"></span> <span class="lishi">捐赠记录</span></a>
	</div>

    <div class="contain">
        <p class="field">请填写捐赠信息</p>
        <p class="form-list">
            <input type="text" maxlength="30" placeholder="捐赠名称(字数不能超过30个)" value="{BEESCRM:$lastOrder.address|default=$user['address']}" id="address" style="border: none;width: 100%;font-size: 14px;">
        </p>
        <p class="form-list">
            <input type="text" placeholder="姓名" value="{BEESCRM:$lastOrder.username|default=$user['real_name']}"
                   id="username" style="border: none;width: 100%;font-size: 14px;">
        </p>


        <p class="form-list">
            <input type="text" placeholder="联系方式" value="{BEESCRM:$lastOrder.mobile|default=$user['mobile']}"
                   id="mobile" style="border: none;width: 100%;font-size: 14px;">
        </p>

    </div>
    <div class="contain">
        <p class="field" style=";color:#00CD00;font-size:15px;" data-price="{BEESCRM:$vo.price}">{BEESCRM:$tree.goods_name}</p>
        <input type="hidden" id="goods_id" value="{BEESCRM:$tree.goods_id}"/>

        <div class="quantity-box clearfix">
            <p class="pull-left">捐赠数量</p>

            <div class="quantity pull-right">
                <span class="iconfont icon-iconfont55 jian"></span>
                <input type="number" value="1" id="buy-num" readonly>
                <span class="iconfont icon-jia jia"></span>
            </div>
        </div>

        <p class="lists price text-right">总计:<span class="total-price" id="money2">{BEESCRM:$tree['price']}元</span></p>
        <input type="hidden" id="price" value="{BEESCRM:$tree.price}"/>
    </div>

    <div class="contain">
        <p class="field"><span style="color: red;">{BEESCRM:$data.content}</span></p>
    </div>

    <div class="btn-box">
        <a href="javascript:void(0);" class="btn btn-confirm">确认</a>
    </div>
</div>

<include file="commonJs"/>
<script src="/assets/base/water/js/jquery-2.1.0.min.js"></script>
<script>
    $(function(){
        $('.close').click(function(){
            $('.cover-wraper').removeClass('flex-box');
        });
    });
</script>
<script type="text/javascript">
    //$('.circle-loadding').show();
    var swiper = new Swiper('.banner .swiper-container', {
        pagination: '.banner .swiper-pagination',
        paginationClickable: true,
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: 2500,
        autoplayDisableOnInteraction: false
    });

    /**
     * 减操作
     */
    $('.jian').on('click', function () {
        var money={BEESCRM:$tree['price']};

        var val = $('#buy-num').val();
        if (val > 1) {
            val = parseInt(val) - 1;

            var money = money * val;
            var money= money.toFixed(2);

            $('#buy-num').val(val);
            $('#price').val(money);
            $('#money2').html(money+'元');
        }
    });

    /**
     * 加树操作
     */
    $('.jia').on('click', function () {
        var money={BEESCRM:$tree['price']}; //单价
        var val = $('#buy-num').val();  //购买数量
        val = parseInt(val) + 1;

        var money = money * val;
        var money= money.toFixed(2);    //总价

        $('#buy-num').val(val);
        $('#price').val(money);
        $('#money2').html(money+'元');
    });


    $(document).on('click', '.btn-confirm', function () {
        postdata();
    });

    /**
     * 提交订单
     * @returns {boolean}
     */
    function postdata() {
        var goods_id=$('#goods_id').val();
        var goods_num = $('#buy-num').val();
        var username = $('#username').val();
        var mobile = $('#mobile').val();
        var address = $('#address').val();
        var money = $('#price').val();

        if (!username) {
			$.alert('error', '请填写姓名');
			return false;
		}
		if (mobile == 0) {
			$.alert('error', '请填写电话');
			return false;
		}
		if(!(/^1[34578]\d{9}$/.test(mobile))) {
			$.alert('error', '电话号码格式错误');
			return false;
		}

        var treeId = "{BEESCRM:$tree_id}";
       // console.log(treeId);
        var info = {};
        info.goods_id=goods_id;
        info.goods_num = goods_num;
        info.address = address;
        info.username = username;
        info.mobile = mobile;
        info.money = money;

        $.ajax({

            'url':"{BEESCRM::U('/Communityhd/giveTree/doSubmitOrder', array('tree_id' => $tree_id))}",
            'data': info,
            'dataType': 'json',
            'type': 'POST',

            success: function (data) {
                if (data.status == 'S') {
                    location.href = data.url;
                } else {
                    fm.alert(data.message);
                    return false;
                }
            }
        })
    }
</script>

</body>
</html>